package com.aistar.line.service.impl;

import com.aistar.line.entity.Line;
import com.aistar.line.mapper.CollectMapper;
import com.aistar.line.mapper.LineMapper;
import com.aistar.line.service.ILineService;
import com.aistar.line.service.IMyCenterService;
import com.aistar.line.vo.LineSpotHotel;
import com.aistar.user.entity.User;
import com.aistar.user.mapper.UserMapper;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: java类作用描述:
 * @Author: tyg
 * @CreateDate: 2019/7/3 0003
 * @Version: 1.0
 */
@Service
@Transactional
public class MyCenterServiceImpl implements IMyCenterService {
    @Autowired
    private CollectMapper collectMapper;

    @Autowired
    private LineMapper lineMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private ILineService lineService;

    @Override
    public Map<String,Object> findByUid() {
//        Claims claims = (Claims) request.getAttribute("claims");

        User user = new User();
//        user.setUsername(claims.getSubject());
//        user.setId(claims.getId());
        user.setId("1");
        user.setUsername("123");

        //根据当前登录用户的id查找其收藏的商品
        List<String> lids = collectMapper.findByUid(user.getId());
        if (null == lids || lids.size() == 0) {
            return null;
        }
        List<LineSpotHotel> list = new ArrayList<>();
        for (String lid : lids) {
            Line line = new Line();
            line.setLineId(lid);
            list.add(lineService.findById(line));
        }
        Map<String,Object> map = new HashMap<>();
        map.put("list",list);
        map.put("user",user);
        return map;
    }
}
